package com.csinc.generate.core.base.log;

import com.csinc.generate.core.base.model.LoginLogModel;
import com.csinc.generate.core.base.model.OperationLogModel;
import com.csinc.generate.core.common.state.LogSucceed;
import com.csinc.generate.core.common.state.LogType;

import java.util.Date;

/**
 * 日志对象创建工厂
 * Create By 郭金宝 on 2018/7/30.<br>
 */
public class LogFactory{


    /**
     * 创建操作日志
     * @param logType
     * @param userId
     * @param bussinessName
     * @param clazzName
     * @param methodName
     * @param msg
     * @param succeed
     * @return
     */
    public static OperationLogModel createOperationLog(LogType logType, Integer userId, String bussinessName, String clazzName, String methodName, String msg, LogSucceed succeed) {
        OperationLogModel operationLog = new OperationLogModel();
        operationLog.setLogtype(logType.getMessage());
        operationLog.setLogname(bussinessName);
        operationLog.setUserid(userId);
        operationLog.setClassname(clazzName);
        operationLog.setMethod(methodName);
        operationLog.setCreatetime(new Date());
        operationLog.setSucceed(succeed.getMessage());
        operationLog.setMessage(msg);
        return operationLog;
    }

    /**
     * 创建登录日志
     * @param logType
     * @param userId
     * @param msg
     * @param ip
     * @return
     */
    public static LoginLogModel createLoginLog(LogType logType, Integer userId, String msg, String ip) {
        LoginLogModel loginLog = new LoginLogModel();
        loginLog.setLogname(logType.getMessage());
        loginLog.setUserid(userId);
        loginLog.setCreatetime(new Date());
        loginLog.setSucceed(LogSucceed.SUCCESS.getMessage());
        loginLog.setIp(ip);
        loginLog.setMessage(msg);
        return loginLog;
    }

}
